
// ajax没有缓存
$.ajaxSetup( {
	cache : false
});
//得到域名
var evn_Path = getPath();
function getPath() {
	//var envPath = document.location.pathname;
	var protoStr = document.location.protocol;
	var hostStr = document.location.host;
	var portStr = document.location.port;
	//var envPathArray = envPath.split('/');
	return protoStr + "//" + hostStr + "/";
}






//除法函数，用来得到精确的除法结果 
//说明：javascript的除法结果会有误差，在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。 
//调用：accDiv(arg1,arg2) 
//返回值：arg1除以arg2的精确结果 
function accDiv(arg1, arg2) {
	var t1 = 0, t2 = 0, r1, r2;
	try {
		t1 = arg1.toString().split(".")[1].length
	} catch (e) {
	}
	try {
		t2 = arg2.toString().split(".")[1].length
	} catch (e) {
	}
	with (Math) {
		r1 = Number(arg1.toString().replace(".", ""))
		r2 = Number(arg2.toString().replace(".", ""))
		return (r1 / r2) * pow(10, t2 - t1);
	}
}
//给Number类型增加一个div方法
//用法： (37).div(3);
Number.prototype.div = function(arg) {
	return accDiv(this, arg);
}

//乘法函数，用来得到精确的乘法结果 
//说明：javascript的乘法结果会有误差，在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。 
//调用：accMul(arg1,arg2) 
//返回值：arg1乘以arg2的精确结果 
function accMul(arg1, arg2) {
	var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
	try {
		m += s1.split(".")[1].length
	} catch (e) {
	}
	try {
		m += s2.split(".")[1].length
	} catch (e) {
	}
	return Number(s1.replace(".", "")) * Number(s2.replace(".", ""))
			/ Math.pow(10, m)
}
//给Number类型增加一个mul方法
//用法： (37).mul(3);
Number.prototype.mul = function(arg) {
	return accMul(arg, this);
}

//加法函数，用来得到精确的加法结果 
//说明：javascript的加法结果会有误差，在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。 
//调用：accAdd(arg1,arg2) 
//返回值：arg1加上arg2的精确结果 
function accAdd(arg1, arg2) {
	var r1, r2, m;
	try {
		r1 = arg1.toString().split(".")[1].length
	} catch (e) {
		r1 = 0
	}
	try {
		r2 = arg2.toString().split(".")[1].length
	} catch (e) {
		r2 = 0
	}
	m = Math.pow(10, Math.max(r1, r2))
	return (arg1 * m + arg2 * m) / m
}
//给Number类型增加一个add方法
//用法： (37).add(3);
Number.prototype.add = function(arg) {
	return accAdd(arg, this);
}

//减法函数，用来得到精确的减法结果 
function Subtr(arg1, arg2) {
	var r1, r2, m, n;
	try {
		r1 = arg1.toString().split(".")[1].length
	} catch (e) {
		r1 = 0
	}
	try {
		r2 = arg2.toString().split(".")[1].length
	} catch (e) {
		r2 = 0
	}
	m = Math.pow(10, Math.max(r1, r2));
	//last modify by deeka
	//动态控制精度长度
	n = (r1 >= r2) ? r1 : r2;
	return ((arg1 * m - arg2 * m) / m).toFixed(n);
}
//给Number类型增加一个add方法
//用法：  (5.5).sub(37.5) 
Number.prototype.sub = function(arg) {
	return Subtr(arg, this);
}

//格式化字符串
/*
用法：
var cls="redclass";
var text="My name is ";
var str='<div class="{0}">{1} {2}</div>'.diy_format(cls, text,"cssrain");
alert(str);
 */
String.prototype.diy_format = function() {
	var args = arguments;
	return this.replace(/\{(\d+)\}/g, function(m, i) {
		return args[i];
	});
}


/**************
 * 字符串前后空格处理。
 * 如果想替换中间的空格，请用replaceAll方法。
 * 用法：
 * "  cssrain   ".trim();
 **************/
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");//将字符串前后空格,用空字符串替代。
}

//提供java的ArrayList的功能
var ArrayList = function() {
	var args = ArrayList.arguments;
	var initialCapacity = 10;

	if (args != null && args.length > 0) {
		initialCapacity = args[0];
	}

	var elementData = new Array(initialCapacity);
	var elementCount = 0;

	this.size = function() {
		return elementCount;
	};

	this.add = function(element) {
		ensureCapacity(elementCount + 1);
		elementData[elementCount++] = element;
		return true;
	};

	this.addElementAt = function(index, element) {
		if (index > elementCount || index < 0) {
			alert("IndexOutOfBoundsException, Index: " + index + ", Size: "
					+ elementCount);
			return;
			//throw (new Error(-1,"IndexOutOfBoundsException, Index: "+index+", Size: " + elementCount));
		}
		ensureCapacity(elementCount + 1);
		for ( var i = elementCount + 1; i > index; i--) {
			elementData[i] = elementData[i - 1];
		}
		elementData[index] = element;
		elementCount++;
	};

	this.setElementAt = function(index, element) {
		//alert("setElementAt");
		if (index > elementCount || index < 0) {
			alert("IndexOutOfBoundsException, Index: " + index + ", Size: "
					+ elementCount);
			return;
			//throw (new Error(-1,"IndexOutOfBoundsException, Index: "+index+", Size: " + elementCount));
		}
		elementData[index] = element;
	};

	this.toString = function() {
		//alert("toString()");
		var str = "{";
		for ( var i = 0; i < elementCount; i++) {
			if (i > 0) {
				str += ",";
			}
			str += elementData[i];
		}
		str += "}";
		return str;
	};

	this.get = function(index) {
		//alert("elementAt");
		if (index >= elementCount) {
			alert("ArrayIndexOutOfBoundsException, " + index + " >= "
					+ elementCount);
			return;
			//throw ( new Error( -1,"ArrayIndexOutOfBoundsException, " + index + " >= " + elementCount ) );
		}
		return elementData[index];
	};

	this.remove = function(index) {
		if (index >= elementCount) {
			alert("ArrayIndexOutOfBoundsException, " + index + " >= "
					+ elementCount);
			//return;
			throw (new Error(-1, "ArrayIndexOutOfBoundsException, " + index
					+ " >= " + elementCount));
		}
		var oldData = elementData[index];
		for ( var i = index; i < elementCount - 1; i++) {
			elementData[i] = elementData[i + 1];
		}
		elementData[elementCount - 1] = null;
		elementCount--;
		return oldData;
	};

	this.isEmpty = function() {
		return elementCount == 0;
	};

	this.indexOf = function(elem) {
		//alert("indexOf");
		for ( var i = 0; i < elementCount; i++) {
			if (elementData[i] == elem) {
				return i;
			}
		}
		return -1;
	};

	this.lastIndexOf = function(elem) {
		for ( var i = elementCount - 1; i >= 0; i--) {
			if (elementData[i] == elem) {
				return i;
			}
		}
		return -1;
	};

	this.contains = function(elem) {
		return this.indexOf(elem) >= 0;
	};

	function ensureCapacity(minCapacity) {
		var oldCapacity = elementData.length;
		if (minCapacity > oldCapacity) {
			var oldData = elementData;
			var newCapacity = parseInt((oldCapacity * 3) / 2 + 1);
			if (newCapacity < minCapacity) {
				newCapacity = minCapacity;
			}
			elementData = new Array(newCapacity);
			for ( var i = 0; i < oldCapacity; i++) {
				elementData[i] = oldData[i];
			}
		}
	}
};


//实现replaceAll功能
String.prototype.replaceAll = function(s1, s2) {
	return this.replace(new RegExp(s1, "gm"), s2);
}


/*初始化年
 *  year:jquery 对象
 * */
function yearInit(year) {
	var date = new Date();
	var currentYear = date.getFullYear();
	var yearOption = "";
	yearOption += "<option value=''> 请选择</option>"
	for ( var i = currentYear; i > currentYear - 60; i--) {
		yearOption += "<option value=" + i + "> " + i + "</option>";
	}
	year.empty();
	$(yearOption).appendTo(year);
}
/*初始化月
 *  month:jquery 对象
 * */
function monthInit(month) {
	var monthOption = "";
	monthOption += "<option value=''> 请选择</option>"
	for ( var i = 1; i < 13; i++) {
		var j = "";
		if (i < 10) {
			j = "0" + i;
		} else {
			j = i;
		}
		monthOption += "<option value=" + j + "> " + i + "</option>";
	}
	month.empty();
	$(monthOption).appendTo(month);
}

/*初始化年月日
 *  birthday:jquery 对象，年月日的上一层
 * */
function yearMonthDay(birthday, strBirthday) {
	var year = birthday.find("#year");
	var month = birthday.find("#month");
	var day = birthday.find("#day");
	yearInit(year);
	monthInit(month);
	var str = "";
	str += "<option value=''>请选择</option>"
	for ( var i = 1; i < 32; i++) {
		var j = "";
		if (i < 10) {
			j = "0" + i;
		} else {
			j = i;
		}
		str += "<option value=" + j + "> " + i + "</option>";
	}
	$(str).appendTo(day);

	/*if (!IsNull(strBirthday)) {
		var a = birthdaySplit(strBirthday);
		year.val(a[0]);
		month.val(a[1]);
		day.val(a[2]);
	}*/

	month.change(function() {
		var yearstr = year.find("option:selected").val();
		var monthstr = month.find("option:selected").text();
		day.empty();
		var str = "<option value=''>请选择</option>";

		if (monthstr == 1 || monthstr == 3 || monthstr == 5 || monthstr == 7
				|| monthstr == 8 || monthstr == 10 || monthstr == 12) {
			for ( var i = 1; i < 32; i++) {
				var j = "";
				if (i < 10) {
					j = "0" + i;
				} else {
					j = i;
				}
				str += "<option value=" + j + "> " + i + "</option>";
			}
			$(str).appendTo(day);
		} else if (monthstr == 2) {
			day.empty();
			if (yearstr % 100 != 0 && yearstr % 4 == 0 || yearstr % 100 == 0
					&& yearstr % 400 == 0) {
				for ( var i = 1; i < 30; i++) {
					var j = "";
					if (i < 10) {
						j = "0" + i;
					} else {
						j = i;
					}
					str += "<option value=" + j + "> " + i + "</option>";
				}
			} else {
				for ( var i = 1; i < 29; i++) {
					var j = "";
					if (i < 10) {
						j = "0" + i;
					} else {
						j = i;
					}
					str += "<option value=" + j + "> " + i + "</option>";
				}
			}
			$(str).appendTo(day);
		} else {
			day.empty();
			for ( var i = 1; i < 31; i++) {
				var j = "";
				if (i < 10) {
					j = "0" + i;
				} else {
					j = i;
				}
				str += "<option value=" + j + "> " + i + "</option>";
			}
			$(str).appendTo(day);
		}
	});
	year.change(function() {
		var yearstr = year.find("option:selected").val();
		var monthstr = month.find("option:selected").text();
		var str = "";
		if (monthstr == 2) {
			day.empty();
			if (yearstr % 100 != 0 && yearstr % 4 == 0 || yearstr % 100 == 0
					&& yearstr % 400 == 0) {
				for ( var i = 1; i < 30; i++) {
					var j = "";
					if (i < 10) {
						j = "0" + i;
					} else {
						j = i;
					}
					str += "<option value=" + j + "> " + i + "</option>";
				}
			} else {
				for ( var i = 1; i < 29; i++) {
					var j = "";
					if (i < 10) {
						j = "0" + i;
					} else {
						j = i;
					}
					str += "<option value=" + j + "> " + i + "</option>";
				}
			}
			$(str).appendTo(day);
		}
	});
}

/**
 * 时间对象的格式化;
 */
Date.prototype.format = function(format) {
	/*
	 * eg:format="YYYY-MM-dd hh:mm:ss";
	 */
	var o = {
		"M+" : this.getMonth() + 1, // month
		"d+" : this.getDate(), // day
		"h+" : this.getHours(), // hour
		"m+" : this.getMinutes(), // minute
		"s+" : this.getSeconds(), // second
		"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
		"S" : this.getMilliseconds()
	// millisecond
	}

	if (/(y+)/.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear() + "")
				.substr(4 - RegExp.$1.length));
	}

	for ( var k in o) {
		if (new RegExp("(" + k + ")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
					: ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return format;
}

//判断对象是否为空
function IsNull(i) {
	return (i == null || i == 'null' || i == '' || i == 'undefined');
}



/**
 * 地址的操作
 * author Bruce Zhang
 * @param provinceId		省/直辖市的ID
 * @param cityId		城市/直辖市的区
 * @param countyId		县/直辖市的街道
 * @param townId		镇
 */
function initProvince(provinceId, cityId, countyId, townId) {
	$.get(evn_Path + "getProvince.htm", function(data) {
		$("#" + provinceId).html("<option value='0'>请选择</option>");
		$("#" + cityId).html("<option value='0'>请选择</option>");
		$("#" + countyId).html("<option value='0'>请选择</option>");
		$("#" + townId).html("<option value='0'>请选择</option>");
		$.each(data, function(i) {
			$("#" + provinceId).append(
					"<option value='" + data[i].province + "'>" + data[i].value
							+ "</option>");
		});
	}, 'json');
	$("#" + provinceId).change(
			function() {
				$.get(evn_Path + "getCity.htm?provinceId="
						+ $("#" + provinceId).val(), function(data) {
					$("#" + cityId).html("<option value='0'>请选择</option>");
					$("#" + countyId).html("<option value='0'>请选择</option>");
					$("#" + townId).html("<option value='0'>请选择</option>");
					$.each(data, function(i) {
						$("#" + cityId).append(
								"<option value='" + data[i].city + "'>"
										+ data[i].value + "</option>");
					});
				}, 'json');
			});

	$("#" + cityId).change(
			function() {
				$.get(evn_Path + "getCounty.htm?cityId="
						+ $("#" + cityId).val(), function(data) {
					$("#" + countyId).html("<option value='0'>请选择</option>");
					$("#" + townId).html("<option value='0'>请选择</option>");
					$.each(data, function(i) {
						$("#" + countyId).append(
								"<option value='" + data[i].county + "'>"
										+ data[i].value + "</option>");
					});
				}, 'json');
			});

	$("#" + countyId).change(
			function() {
				$.get(evn_Path + "getTown.htm?countyId="
						+ $("#" + countyId).val(), function(data) {
					$("#" + townId).html("<option value='0'>请选择</option>");
					$.each(data, function(i) {
						$("#" + townId).append(
								"<option value='" + data[i].town + "'>"
										+ data[i].value + "</option>");
					});
				}, 'json');
			});
}

function provinceChange(provinceId, cityId, countyId, townId, provinceValue,
		cityValue, countyValue, townValue) {
	$.get(evn_Path + "getProvince.htm", function(data) {
		$("#" + provinceId).html("<option value='0'>请选择</option>");
		$("#" + cityId).html("<option value='0'>请选择</option>");
		$("#" + countyId).html("<option value='0'>请选择</option>");
		$("#" + townId).html("<option value='0'>请选择</option>");
		$.each(data, function(i) {
			if (data[i].province == provinceValue) {
				$("#" + provinceId).append(
						"<option selected value='" + data[i].province + "'>"
								+ data[i].value + "</option>");
			} else {
				$("#" + provinceId).append(
						"<option value='" + data[i].province + "'>"
								+ data[i].value + "</option>");
			}

		});
		//////////////////
			$.get(evn_Path + "getCity.htm?provinceId=" + provinceValue,
					function(data) {
						$("#" + cityId).html("<option value='0'>请选择</option>");
						$("#" + countyId)
								.html("<option value='0'>请选择</option>");
						$("#" + townId).html("<option value='0'>请选择</option>");
						$.each(data, function(i) {
							if (data[i].city == cityValue) {
								$("#" + cityId).append(
										"<option selected value='"
												+ data[i].city + "'>"
												+ data[i].value + "</option>");
							} else {
								$("#" + cityId).append(
										"<option value='" + data[i].city + "'>"
												+ data[i].value + "</option>");
							}

						});
						//////////////
					$.get(evn_Path + "getCounty.htm?cityId=" + cityValue,
							function(data) {
								$("#" + countyId).html(
										"<option value='0'>请选择</option>");
								$("#" + townId).html(
										"<option value='0'>请选择</option>");
								$.each(data, function(i) {
									if (data[i].county == countyValue) {
										$("#" + countyId).append(
												"<option selected value='"
														+ data[i].county + "'>"
														+ data[i].value
														+ "</option>");
									} else {
										$("#" + countyId).append(
												"<option value='"
														+ data[i].county + "'>"
														+ data[i].value
														+ "</option>");
									}

								});
								///////////////
							$.get(evn_Path + "getTown.htm?countyId="
									+ countyValue, function(data) {
								$("#" + townId).html(
										"<option value='0'>请选择</option>");
								$.each(data, function(i) {
									if (data[i].town == townValue) {
										$("#" + townId).append(
												"<option selected value='"
														+ data[i].town + "'>"
														+ data[i].value
														+ "</option>");
									} else {
										$("#" + townId).append(
												"<option value='"
														+ data[i].town + "'>"
														+ data[i].value
														+ "</option>");
									}

								});
							}, 'json');
							//////////////
						}, 'json');
					///////////
				}, 'json');
			/////////////////
		}, 'json');

	$("#" + provinceId).change(
			function() {
				$.get(evn_Path + "getCity.htm?provinceId="
						+ $("#" + provinceId).val(), function(data) {
					$("#" + cityId).html("<option value='0'>请选择</option>");
					$("#" + countyId).html("<option value='0'>请选择</option>");
					$("#" + townId).html("<option value='0'>请选择</option>");
					$.each(data, function(i) {
						$("#" + cityId).append(
								"<option value='" + data[i].city + "'>"
										+ data[i].value + "</option>");
					});
				}, 'json');
			});

	$("#" + cityId).change(
			function() {
				$.get(evn_Path + "getCounty.htm?cityId="
						+ $("#" + cityId).val(), function(data) {
					$("#" + countyId).html("<option value='0'>请选择</option>");
					$("#" + townId).html("<option value='0'>请选择</option>");
					$.each(data, function(i) {
						$("#" + countyId).append(
								"<option value='" + data[i].county + "'>"
										+ data[i].value + "</option>");
					});
				}, 'json');
			});

	$("#" + countyId).change(
			function() {
				$.get(evn_Path + "getTown.htm?countyId="
						+ $("#" + countyId).val(), function(data) {
					$("#" + townId).html("<option value='0'>请选择</option>");
					$.each(data, function(i) {
						$("#" + townId).append(
								"<option value='" + data[i].town + "'>"
										+ data[i].value + "</option>");
					});
				}, 'json');
			});
}




(function(d) {
	
		
		
	
//取得光标位置和选中的文本
	d.fn.selection = function() {
		var s, e, range, stored_range;
		if (this[0].selectionStart == undefined){
			var selection = document.selection;
			if (this[0].tagName.toLowerCase() != "textarea") {
				var val = this.val();
				range = selection.createRange().duplicate();
				range.moveEnd("character", val.length);
				s = (range.text == "" ? val.length : val
						.lastIndexOf(range.text));
				range = selection.createRange().duplicate();
				range.moveStart("character", -val.length);
				e = range.text.length;
			} else {
				range = selection.createRange(), stored_range = range
						.duplicate();
				stored_range.moveToElementText(this[0]);
				stored_range.setEndPoint('EndToEnd', range);
				s = stored_range.text.length - range.text.length;
				e = s + range.text.length;
			}
		} else {
			s = this[0].selectionStart, e = this[0].selectionEnd;
		}
		var te = this[0].value.substring(s, e);
		return {
			start : s,
			end : e,
			text : te
		}
	};
	
	d.fn.ImageAutoSize = function(width, height) {
		$("img", this).each(function() {
			var image = $(this);
			if (image.width() > width) {
				image.width(width);
				image.height(width / image.width() * image.height());
			}
			if (image.height() > height) {
				image.height(height);
				image.width(height / image.height() * image.width());
			}
		});
	}
	//记录光标的地方，从光标的地方插入
	d.fn.extend({
		insertAtCaret : function(myValue) {
			var $t = $(this)[0];
			if (document.selection) {
				this.focus();
				sel = document.selection.createRange();
				sel.text = myValue;
				this.focus();
			} else if ($t.selectionStart || $t.selectionStart == '0') {
				var startPos = $t.selectionStart;
				var endPos = $t.selectionEnd;
				var scrollTop = $t.scrollTop;
				$t.value = $t.value.substring(0, startPos) + myValue
						+ $t.value.substring(endPos, $t.value.length);
				this.focus();
				$t.selectionStart = startPos + myValue.length;
				$t.selectionEnd = startPos + myValue.length;
				$t.scrollTop = scrollTop;
			} else {
				this.value += myValue;
				this.focus();
			}
		}
	})
// 果果街专属
	GUOGUO = {
		checkLogin : function(){
			var isLogin = false;
			$.ajax({
				type:"post",
				async:false, //同步
				url: "/member/checklogin.htm",
				success:function(data){
					if(data=='logged'){
						isLogin = true;
					}
				}
			});
			return isLogin;	
		},
		joinPictorial : function(picproId,picType,page){
			if($("#join_pic_dialog").size() < 1){
				$(document.body).append('<div class="ejectWraper" id="join_pic_dialog" style="position:absolute;z-index:200;"></div>');
			}
			if(IsNull(page)){
				page = 1;
			}
			$("#join_pic_dialog").empty().load("joinPicDialog.htm?picproId="+picproId+"&picType="+picType+"&page="+page,function(){
				showDivMiddle("join_pic_dialog");
			});
			
		},
		unMessage : function(){
			//定时刷新
				$.post("/messageheader.htm",function(data){
					if(!IsNull(data) && data >0){
						$("#message").show();
						$("#message").empty();
						//alert("111111");
						var msgAll = '<span class="up_arrow_s1">arrow</span> <a href="/message.htm">您有'+data+'条新消息</a>';
						$("#message").append(msgAll);
					}
					var messageNew = $("#message span");
					if(messageNew.size()>0){
						$("#messageHui").hide();
						$("#messageRed").show();
					}
					setTimeout("GUOGUO.unMessage()",6000);
				});
			},
			deleteMessage : function(messageId){
				if(confirm("你确定要删除吗？")){
					$.post("pmessageDelete.htm",{
						"messageId":messageId
					},function(data){
						if(data == 'success'){
							window.location.reload();
						}
					});
				}
				
			},
			/*$.post("unReadMessage.htm",function(data){
				
				if(!IsNull(data) && !IsNull(data.notify)){
					var newNotify = '<li id="message_notify_li_notify"><a href="notify.htm">新通知<span>('+data.notify+')</span></a></li>';
					if($("#message_notify_li_notify").size()> 0){
						$("#message_notify_li_notify").remove();
					}
					$("#notice_menu").prepend(newNotify);
				}
				* 
				if(!IsNull(data) && !IsNull(data.pmsg)){
					var newInfo = '<span>('+data.pmsg+')</span>';
						$("#message_notify_li_pmsg span").remove();
					$("#message_notify_li_pmsg").append(newInfo);
				}
				
				if(!IsNull(data) && !IsNull(data.comment)){
					var newInfo = '<span>('+data.comment+')</span>';
						$("#message_notify_li_comment span").remove();
					$("#message_notify_li_comment").append(newInfo);
				}
				if(!IsNull(data) && !IsNull(data.at)){
					var newInfo = '<span>('+data.at+')</span>';
						$("#message_notify_li_at span").remove();
					$("#message_notify_li_at").append(newInfo);
				}
				if(!IsNull(data) && !IsNull(data.fans)){
					var newInfo = '<span>('+data.fans+')</span>';
						$("#message_notify_li_fans span").remove();
					$("#message_notify_li_fans").append(newInfo);
				}
				if(!IsNull(data) && !IsNull(data.msgCount)){
					var msgAll = '消息(<b>'+data.msgCount+'</b>)';
					$("#message_notify").empty();
					$("#message_notify").append(msgAll);
				}
				setTimeout("GUOGUO.unReadMessage()",6000);
			},'json');
		},*/
		
		familyTip : function(nickname,obj,memberId){
			if($("#family_tip").size() < 1){
				$(document.body).append("<div class='ggann' id='family_tip'></div>");
			}
			if(!IsNull(nickname)){
				if(nickname != $("#family_tip").find(".name").html()){
					$("#family_tip").html("");
				}
			}
			$("#family_tip").hover(function(){
				$(this).show();
			},function(){
				$(this).hide();
			});
			var loc = GGTOOL.getAbsoluteLocation(obj);
			var objWidth = $(obj).width();
			var objHeight = $(obj).height()+7;
			$("#family_tip").css("top",loc.absoluteTop+objHeight);
			$("#family_tip").css("left",loc.absoluteLeft-60+objWidth/2);
			if(!IsNull(nickname)){
				$("#family_tip").show().load("avatarInfo.htm?nickname="+encodeURI(nickname));
			}else if(!IsNull(memberId)){
				$("#family_tip").show().load("avatarInfo.htm?memberId="+memberId);
			}
			
		},
		hideFamilyTip : function(){
			$("#family_tip").hide();
		},
		doingForwardDialog : function(obj){
			if($("#lb_forward").size() < 1){
				$(document.body).append('<div id="lb_forward" class="light_box" style="width:460px;"></div>');	
			}
			var doingId = $(obj).attr("doingId");
			$("#lb_forward").load("forwardDialog.htm?doingId="+doingId).show();
			showDivMiddle("lb_forward");
		},
		
		
		remain:function(textarea, remain, max){
			$("#" + remain).show();
			var content = $("#" + textarea).val();
			//最多输入数字
			//取得用户输入的字符长度
			var length;
			if (content.indexOf("#输入话题标题#") >= 0) {
				length = content.length - 8;
			} else {
				length = content.length;
			}
			if (length <= max) {
				$("#" + remain)
						.html("&nbsp;还能输入 <font size='3' id='remain'>" + (max - length)
										+ "</font> 字");
				return true;
			} else {
				$("#" + remain).html(
						"&nbsp;超出 <font size='3'color='red' id='remain'>" + (length - max)
								+ "</font> 字");
				return false;
			}
		},
		//喜欢
		 loveDoing:function(doingId){
			if(GUOGUO.checkLogin()){
				$.get("/loveDoing.htm?doingId="+doingId,function(data){
					if(data=="alreadyLove"){
						alert("你已经收藏过了");
					}else if(data == "loveSuccess"){
						alert("收藏成功");
					}
				}); 
			}else{
				GUOGUO.memberLogin();
			}
		},
//		登录弹出框
		 memberLogin:function(){
			$.get("/member/checklogin.htm",function(data){
				if(data=="nologin"){
					if($('#tc_div').length<1){
						$('body').append('<div id="tc_div"></div>');
					}
					$('#tc_div').load("/member/poplogin.htm",function(data){
						$.fn.popDiv({
							tcID:"tc_box",opacity:0.4,isZZ:true,speed:200,noResize:true
						});
					});
				}
			});
		}
	}
//  工具类	
	GGTOOL = {
        distance2Bottom: function(a) {
            var c = d(document).scrollTop(),
            b = d(window).height(),
            g = d(document).height();
            return c + b + a >= g ? !0 : !1
        },
//        去空格
        trim: function(a) {
            return a.replace(/(^\s*)|(\s*$)/g, "").replace(/(^\u3000*)|(\u3000*$)/g, "")
        },
        isURl: function(a) {
            return /([\w-]+\.)+[\w-]+.([^a-z])(\/[\w-.\/?%&=]*)?|[a-zA-Z0-9\-\.][\w-]+.([^a-z])(\/[\w-.\/?%&=]*)?/i.test(a) ? !0 : !1
        },
        //得到字符串的字节长度
        byteLength: function(a) {
            var c = a.match(/[^\x00-\x80]/g);
            return a.length + (!c ? 0 : c.length)
        },
        //得到字符串的长度
        getMsgLength: function(a) {
            var c = a.length;
            if (c > 0) {
                for (var b = a,
                a = a.match(/http[s]?:\/\/[a-zA-Z0-9-]+(\.[a-zA-Z0-9]+)+([-A-Z0-9a-z_\$\.\+\!\*\(\)\/\/,:;@&=\?\~\#\%]*)*/gi) || [], d = 0, e = 0, c = a.length; e < c; e++) {
                    var f = GGTOOL.byteLength(a[e]);
                    /^(http:\/\/mogujie.cn)/.test(a[e]) || (d += /^(http:\/\/)+(mogujie.cn|mogujie.com)/.test(a[e]) ? f <= 41 ? f: f <= 140 ? 24 : f - 140 + 24 : f <= 140 ? 24 : f - 140 + 24, b = b.replace(a[e], ""))
                }
                return Math.ceil((d + GGTOOL.byteLength(b)) / 2)
            } else return 0
        },
        jsMbSubstr: function(a, c) {
            if (!a || !c) return "";
            for (var b = 0,
            d = 0,
            e = "",
            d = 0; d < a.length; d++) {
                a.charCodeAt(d) > 255 ? b += 2 : b++;
                if (b > c * 2) return e;
                e += a.charAt(d)
            }
            return a
        },
//        得到对象的绝对位置
        getAbsoluteLocation: function(a) {
            if (arguments.length != 1 || a == null) return null;
            var c = d(a),
            b = c.offset(),
            g = b.top,
            b = b.left,
            c = c.height(),
            e = d(window).height(),
            f = d(document).scrollTop();
            return {
                absoluteTop: g,
                absoluteLeft: b,
                isInView: g >= f && g <= f + e,
                isLoad: g + c + 200 >= f && g - 400 <= f + e
            }
        },
        objToJson: function(a) {
            var c = "{",
            b;
            for (b in a) a[b] != null && (c += typeof a[b] === "object" ? '"' + b + '":' + GGTOOL.objToJson(a[b]) + ",": '"' + b + '":"' + a[b] + '",');
            c += "}";
            return c = c.replace(/,}/g, "}")
        },
        //得到图片的后缀名
        getPicExtension: function(a) {
            return a.toLowerCase().substring(a.lastIndexOf(".") + 1)
        },
        //是否为空
        empty: function(a) {
            return void 0 === a || null === a || "" === a
        },
        //对象是否为空
        emptyObj: function(a) {
            for (var c in a) return ! 1;
            return ! 0
        },
        isParent: function(a, c) {
            for (; a != void 0 && a != null && a.tagName.toUpperCase() != "BODY";) {
                if (a == c) return ! 0;
                a = a.parentNode
            }
            return ! 1
        },
        setCookie: function(a, c, b) {
            b = b || {};
            if (c === null) c = "",
            b.expires = -1;
            var d = "";
            if (b.expires && (typeof b.expires == "number" || b.expires.toUTCString)) typeof b.expires == "number" ? (d = new Date, d.setTime(d.getTime() + b.expires * 864E5)) : d = b.expires,
            d = "; expires=" + d.toUTCString();
            var e = b.path ? "; path=" + b.path: "",
            f = b.secure ? "; secure": "",
            h = "";
            null != b.domain || void 0 != b.domain ? h = "; domain=" + b.domain: (h = document.domain.toString().split("."), h = "; domain=." + h[1] + "." + h[2]);
            document.cookie = [a, "=", encodeURIComponent(c), d, e, h, f].join("")
        },
        getCookie: function(a) {
            a = document.cookie.match(RegExp("(^| )" + a + "=([^;]*)(;|$)"));
            if (a != null) return unescape(a[2]);
            return ""
        },
//        得到对象的鼠标位置
        getMousePosition: function(a) {
            var c = 0,
            b = 0;
            if (!a) a = window.event;
            if (a.pageX || a.pageY) c = a.pageX,
            b = a.pageY;
            else if (a.clientX || a.clientY) c = a.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
            b = a.clientY + document.body.scrollTop + document.documentElement.scrollTop;
            return {
                x: c,
                y: b
            }
        },
        getQueryString: function(a) {
            if (RegExp("(^|\\?|&)" + a + "=([^&]*)(\\s|&|$)", "i").test(location.href)) return unescape(RegExp.$2.replace(/\+/g, " "));
            return ""
        },
//        是否是苹果的IOS系统
        isIOS: function() {
            return /\((iPhone|iPad|iPod)/i.test(navigator.userAgent)
        },
		/**
		 日期相加
		 * strType：要加的日期是秒，分钟，小时，天数，周数等
		 * num：加的数
		 * dtTmp：要被加的日期，类型为Date
		 */
		dateAdd : function(strType, num, dtTmp) {
			if (isNaN(dtTmp))
				dtTmp = new Date();
			switch (strType) {
			//秒
			case "s":
				dtTmp = new Date(Date.parse(dtTmp) + (1000 * parseInt(num)));
				break;
			//		分钟
			case "n":
				dtTmp = new Date(Date.parse(dtTmp) + (60000 * parseInt(num)));
				break;
			//		小时
			case "h":
				dtTmp = new Date(Date.parse(dtTmp) + (3600000 * parseInt(num)));
				break;
			//		天数
			case "d":
				dtTmp = new Date(Date.parse(dtTmp) + (86400000 * parseInt(num)));
				break;
			//		周数
			case "w":
				dtTmp = new Date(Date.parse(dtTmp) + ((86400000 * 7) * parseInt(num)));
				break;
			//		月数
			case "m":
				dtTmp = new Date(dtTmp.getFullYear(), (dtTmp.getMonth())
						+ parseInt(num), dtTmp.getDate(), dtTmp.getHours(), dtTmp
						.getMinutes(), dtTmp.getSeconds());
				break;
			//		年数
			case "y":
				dtTmp = new Date(dtTmp.getFullYear() + parseInt(num), dtTmp.getMonth(),
						dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp
								.getSeconds());
				break;
			}

			return dtTmp;
		},
		getWeekDay : function(date){
			if (IsNull(date))
				date = new Date();
			var x = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
			return (x[date.getDay()]);
		},
		/**
		 将字符串转换成日期
		 * 格式：yyyy-MM-dd hh:mm:ss
		 */
		strToDate : function(str){
			var strArray = str.split(" ");
			var ymd = strArray[0];
			var ymdArray = ymd.split("-");
			var parseDate = ymdArray[1] + "/" + ymdArray[2] + "/" + ymdArray[0];
			if (!IsNull(strArray[1])) {
				parseDate += " ";
				parseDate += strArray[1];
			}
			var val = Date.parse(parseDate);
			var newDate = new Date(val);
			return newDate;
		},
		//字符转换成html格式编码
		htmlEncode: function(str){
			var s = "";
			if (str.length == 0)
				return "";
			s = str.replace(/&/g, "&gt;");
			s = s.replace(/</g, "&lt;");
			s = s.replace(/>/g, "&gt;");
			s = s.replace(/ /g, "&nbsp;");
			s = s.replace(/\'/g, "&#39;");
			s = s.replace(/\"/g, "&quot;");
			s = s.replace(/\n/g, "<br>");
			return s;
		},
		//解码
		htmlDecode : function(str){
			var s = "";
			if (str.length == 0)
				return "";
			s = str.replace(/&gt;/g, "&");
			s = s.replace(/&lt;/g, "<");
			s = s.replace(/&gt;/g, ">");
			s = s.replace(/&nbsp;/g, " ");
			s = s.replace(/&#39;/g, "\'");
			s = s.replace(/&quot;/g, "\"");
			s = s.replace(/<br>/g, "\n");
			return s;
		},
		
		//得到url参数值
		// url: http:www.cssrain.cn/article.asp?id=100
		// var id = getParameter("id");
		// alert(id);
	 	getParameter:function(key){
			var parameters = unescape(window.location.search.substr(1)).split("&");
			for( var i = 0 ; i < parameters.length ; i++ ){
				var paramCell = parameters[i].split("=");
				if( paramCell.length == 2 && paramCell[0].toUpperCase() == key.toUpperCase() )
				{
					return paramCell[1];
				}
			}
			return new String();
		},
		//获取某月有几天 ，月份是从 0开始
		//用法：alert(  jscomGetMonthDays(2008 ,  4)   )
		jscomGetMonthDays : function(year,month){
			if(month<0 || month>11){
				return 30;
			}
			var arrMon = new Array(12);
			arrMon[0] = 31;
			if(year % 4 == 0){
				arrMon[1] =29;
			}else{
				arrMon[1] =28;
			}	
			arrMon[2] = 31;	arrMon[3] = 30;
			arrMon[4] = 31;	arrMon[5] = 30;
			arrMon[6] = 31;	arrMon[7] = 31;
			arrMon[8] = 30;	arrMon[9] = 31;
			arrMon[10] = 30;arrMon[11] = 31;	
			return arrMon[month];
		},
		/**
		 * 以document.write的方式向页面中写入js
		 * 参数 ： 
		 o {
		   id : id of the created tag, 
		   url : String,
		   script  : String
		  }
		 用法： dwScript({id : 'cssrain'  , url :  'js/fl.js' });
		 */
		dwScript : function(o){
			o.id = o.id || "";
		  	o.charset = o.charset || "utf-8";
		  	if (o.script && o.script != ""){
		    	document.write("<script id='" + o.id + "'>" + o.script + "<\/script>");
		  	}else if (o.url && o.url != ""){
		    	document.write("<script id='" + o.id + "' src='" + o.url + "' charset='" + o.charset + "'><\/script>");
		  	}else throw new Error("no script content or url specified");
		},
		/**
		 * 以document.write的方式向页面中写入css
		 * @param o {
		 *    id : id of the created tag, 
		 *    url : String,
		 *    styles  : styles text
		 *  }
		用法：dwCSS({ id :  'cssrain'  , url:'css/default.template.css?'});
		 */
		dwCSS : function(o){
			o.id = o.id || "";
			if (o.url){
			  document.write('<link id="' + o.id + '" rel="stylesheet" type="text/css" href="' + o.url + '" />');
			} else if (o.styles){
			  document.write('<style id="' + o.id + '" >'+o.styles+'<\/style>');
			} 
		},
		/**
		 * 把字符串中 的 半角 转换为全角。
		 用法：
		 var a  =  "d'd'd'd()%[]";
		 alert(toSafe(a));
		
		 当然可以用于表单的值转换。
		 */
		toSafe : function(str){
			var re;
			re = /'/g;
			str = str.replace(re,"＇");
			re =/\)/g;
			str = str.replace(re,"）");
			re = /\(/g;
			str = str.replace(re,"（");
			re = /%/g;
			str = str.replace(re,"％");
			re = /\[/;
			str = str.replace(re,"［");
			re = /\]/;
			str = str.replace(re,"］");
			return str;
		},
		//表单内的输入框的内容转换
		makeToSafe : function(formName){
			var i,form;
			form = eval(formName);
			for(i=0;i<form.elements.length;i++)
			{
				if(form.elements[i].type=="text" || form.elements[i].type=="textarea")
				{
					form.elements[i].value = toSafe(form.elements[i].value);
				}
			}
		},
		/*
		   小数   四舍五入
		//Dight 为要转换的数据
		//How  要保留的小数位数
		 用法:
		var k = ForDight(  222.5  ,  0 )  ;
		 */
		forDight : function(Dight,How){
			Dight = Math.round (Dight*Math.pow(10,How))/Math.pow(10,How); 
			return Dight; 
		},
		//   计算日期为当年的第几周     
		//   用法：    
		//   获取   2008-7-5  为当年的第几周     
		//   返回:  28     
		// document.write(  weekOfYear(2008 ,7 ,5)); 
		weekOfYear : function(year,month,day){
			 //   year       年     
		      //   month     月     
		      //   day         日     
		      //   每周从周日开始     
		      var   date1   =   new   Date(year,   0,   1);     
		      var   date2   =   new   Date(year,   month-1,   day,   1);     
		      var   dayMS   =   24*60*60*1000;     
		      var   firstDay   =   (7-date1.getDay())*dayMS;     
		      var   weekMS   =   7*dayMS;     
		      date1   =   date1.getTime();     
		      date2   =   date2.getTime();     
		      return   Math.ceil((date2-date1-firstDay)/weekMS)+1;    
		},
		//   通过周数和星期计算日期  
		//   获取   2005   年第   37   周的周六的日期   。 (0-6,   0代表周日)       
		//   返回:   2005年9月10号     
		//   alert(dateFromWeek(2005,   37,   6)); 
		dateFromWeek : function(year,week,day){
			//   year       年     
		      //   week       周     
		      //   day         星期   (0-6,   0代表周日)     
		      var   date1   =   new   Date(year,   0,   1);     
		      var   dayMS   =   24*60*60*1000;     
		      var   firstDay   =   (7-date1.getDay())*dayMS;     
		      var   weekMS   =   (week-2)*7*dayMS;     
		      var   result   =   date1.getTime()+firstDay+weekMS+day*dayMS;     
		      date1.setTime(result);     
		      return   date1.toLocaleDateString();  
		},
		/**************
		收藏到书签.(兼容IE和FF)。
		用法:
		<input type="button" value="收藏" onclick="addBookmark('cssrain(前端开发)','http://www.cssrain.cn')"/> 
		**************/
		addBookmark : function(title,url){
			if (window.sidebar) {
				window.sidebar.addPanel(title, url,"");
			} else if( document.all ) {
				window.external.AddFavorite( url, title);
			} else if( window.opera && window.print ) {
				return true;
			}
		},
		/**************
		函数 ： 文本框得到与失去焦点 操作。
		这个方法经常在文本框搜索的时候出现。
		文本里显示 “ 搜索 ”，然后当用户鼠标点击此文本，
		文本框内容清空。如果用户没填写内容，那么文本的值又复原。
		如果填写了，就显示用户填写的。
		 用法:
		 <input type="" value="关键字搜索" name="a" onfocus="clearTxt('a','关键字搜索')" onblur="fillTxt('a','关键字搜索')"/>
		<input type="text" value="test" name="test" />
		**************/
		clearTxt : function(id,txt){
			if (document.getElementById(id).value == txt)
		    document.getElementById(id).value="" ;
		  return ;
		},
		fillTxt : function(id,txt){
			if ( document.getElementById(id).value == "" )
		    document.getElementById(id).value=txt;
		  return ;
		},
		/**************
		文本框输入字符控制。
		只能输入数字。
		用法:
		<input onkeyup="inputNumber(this)" />
		**************/
		inputNumber : function(obj){
			obj.value=obj.value.replace(/[^\d]/g,'');
		}
	};
})(jQuery);
			


/**
 * @author grieous
 * 幸运排名弹出框
 */
function luckRank(){
	$.post("/luck/luckrank.htm",function(data){
		if(data!="noLuckTime"){
			if($('#luck_rank').length<1){
				$('body').append('<div id="luck_rank"></div>');
			}
			$('#luck_rank').load("/luck/luckrank.htm",function(data){
				if(data!="noLuckTime"){
					$.fn.popDiv({
						tcID:"tc_box",opacity:0.4,isZZ:true,speed:200,noResize:true
					});
					$("#a_rank").bind("click",function(){
						rank();
						$(this).unbind('click');
					});
				}
			});
		}
	});
}

/**
 * @author grieous
 * 获取排名
 */
function rank() {
	$("#result").show();
	num();
	setTimeout('clearNum()',6000);

}
function clearNum(){
	$.post("/luck/luckranknum.htm",function(data){
		clearTimeout(T);
		$("#num").html(data.currentRankNum);
		$("#sort_rank").show().html(data.sortResult);
	},'json');
}
function num(){
	var num = Math.round(Math.random() * (99999));
    var span_num = $("#num");
    if (span_num.length>0) {
    	span_num.html(num);
    }
    T = setTimeout('num()', 10);
}


//添加关注
function addFans(f,t){
	if(GUOGUO.checkLogin()){
		$.post("/member/addfans.htm",{follow:f},function(data){
			var html='';
			if(data=="success"){
				if(t=='cover'){
					$("#cover_add_gz").html('<span class="already_gz" style="display: inline-block;">已关注</span><a href="javascript:void(0)" class="ml10" onclick="cancelFans(\''+f+'\',\'cover\');">取消</a><a href="#" class="send">给TA发私信</a>');
				}else{
					$("#list_gz_fans_"+f).html('<span>已关注</span>');
				}
			}
		});
	}else{
		GUOGUO.memberLogin();
	}
	
}

//取消关注
function cancelFans(f,c){
	if(GUOGUO.checkLogin()){
		$.post("/member/cancelfans.htm",{follow:f},function(data){
			if(data=="success"){
				$("#cover_add_gz").html('<a href="javascript:void(0)" class="add_gz" onclick="addFans(\''+f+'\',\''+c+'\');">+&nbsp;关注</a><a href="#" class="send">给TA发私信</a>');
			}
		});
	}else{
		GUOGUO.memberLogin();
	}
	
}
//发站内信
function sendMsg(member) {
	if(GUOGUO.checkLogin()){
		var size = $("#msgWindows").size();
		if (size < 1) {
			$("body").append( ' <div class="release_box send_mes tc_box" id="msgWindows" style="display: none;"></div>');
		}
		$("#msgWindows").load("/msgMember.htm?receiveId="+member,function(){
			/*alert(member);*/
			$.fn.popDiv({
				tcID:"msgWindows",isZZ:false,speed:200,noResize:false
			});	
		});
	}else{
		GUOGUO.memberLogin();
	}
}

/**
 * author BruceZhang
 * 分享商品
 */
function sharelink(){
	if(GUOGUO.checkLogin()){
		if($("#share_link_dialog").size() < 1){
			$(document.body).append("<div id='share_link_dialog'></div>");
		}
		$("#share_link_dialog").load("/tosharelink.htm");
	}else{
		GUOGUO.memberLogin();
	}
}

/**
 * 分享到微博
 * author Grieous
 * @param shareType 微博类型：01-新浪微博 03-腾讯微博
 * @param picurl 图片地址如:http://www.guoguojie.com/pic/background/20120920/100016598/69fc85b0-1a3e-4c0f-96aa-74f736aa9bbf.jpg
 * @param picurl 分享链接如:http://www.guoguojie.com/rebate/rebate.htm
 */
function shareWeibo(shareType,text,picurl,shareurl){
	if(GUOGUO.checkLogin()){
		text = encodeURI(text);   
		text = encodeURI(text);   
		var url="/weibo/share.htm?shareType="+shareType+"&text="+text+"&picurl="+picurl+"&shareurl="+shareurl;
		window.open(url);
	}else{
		GUOGUO.memberLogin();
	}
}